package com.example.service.impl;

import com.example.dto.StudentCountDto;
import com.example.dto.StudentDegreeDataDto;
import com.example.mapper.EmpMapper;
import com.example.mapper.StudentMapper;
import com.example.service.ReportService;
import com.example.vo.report.JobOption;
import com.example.vo.report.StudentCount;
import com.example.vo.report.StudentDegreeData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;
    public JobOption getEmpJobData() {
        List<Map<String,Object>> list = empMapper.countEmpJobData();
        List<Object> jobList = new ArrayList<>();
        List<Object> dataList = new ArrayList<>();
        for (Map<String, Object> map : list) {
            jobList.add(map.get("pos"));
            dataList.add(map.get("total"));
        }

        return new JobOption(jobList, dataList);
    }

    public List<Map> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }

    public StudentCount getStudentCount() {
        List<String> clazzList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();
        List<StudentCountDto> list = studentMapper.getStudentCount();
        for (StudentCountDto studentCountDto : list) {
            clazzList.add(studentCountDto.getName());
            dataList.add(studentCountDto.getCount());
        }
        return new StudentCount(clazzList, dataList);
    }
    public List<StudentDegreeDataDto> getStudentDegreeData(){
        List<StudentDegreeDataDto> list = studentMapper.getStudentDegreeData();
        for (StudentDegreeDataDto studentDegreeDataDto : list){
            if(studentDegreeDataDto.getName().equals("1")){
                studentDegreeDataDto.setName("初中");
            }
            else if(studentDegreeDataDto.getName().equals("2")){
                studentDegreeDataDto.setName("高中");
            }
            else if(studentDegreeDataDto.getName().equals("3")){
                studentDegreeDataDto.setName("大专");
            }
            else if(studentDegreeDataDto.getName().equals("4")){
                studentDegreeDataDto.setName("本科");
            }
            else if(studentDegreeDataDto.getName().equals("5")){
                studentDegreeDataDto.setName("硕士");
            }
            else if(studentDegreeDataDto.getName().equals("6")){
                studentDegreeDataDto.setName("博士");
            }
        }
        return list;
    }
}
